package com.gt.web.srv.web.api.command;

import cn.hutool.core.util.IdcardUtil;
import com.gt.web.api.exception.BusinessException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.regex.Pattern;

/**
 * 注册绑定入参
 *
 * @author Yu Chaohua
 * @date 2024/5/18 23:14
 */
@Data
@ApiModel(description = "绑定用户信息入参")
public class RegisterPeopleCommand {


    @NotBlank(message = "真实姓名不能空")
    @ApiModelProperty(value = "真实姓名")
    private String peopleName;

    @ApiModelProperty(value = "手机", required = true)
    @NotBlank(message = "手机不能为空")
    private String peopleMobile;

    @ApiModelProperty(value = "身份证号")
    @NotBlank(message = "身份证不能为空")
    private String peopleCard;

    @ApiModelProperty(value = "社区ID")
    @NotNull(message = "社区ID")
    private Long communityId;

    @ApiModelProperty(value = "住址")
    private String peopleAddress;


    public void check() {

        if (!IdcardUtil.isValidCard(this.peopleCard)) {
            throw new BusinessException(3000, "身份证号格式不对");
        }
        if (!Pattern.matches("^1[3-9]\\d{9}$", peopleMobile)) {
            throw new BusinessException(3001, "手机号格式不对");
        }
        if (this.communityId <= 0) {
            throw new BusinessException(3002, "社区不能空");
        }
    }
}
